exports_files(["gtest.h"])

cc_library(
    name = "kj-tls",
    srcs = [
        "readiness-io.c++",
        "tls.c++",
    ],
    hdrs = [
        "readiness-io.h",
        "tls.h",
    ],
    include_prefix = "kj/compat",
    target_compatible_with = select({
        "//src/kj:use_openssl": [],
        "//conditions:default": ["@platforms//:incompatible"],
    }),
    visibility = ["//visibility:public"],
    deps = [
        "//src/kj:kj-async",
        "@ssl",
    ],
)

cc_library(
    name = "kj-http",
    srcs = [
        "http.c++",
        "url.c++",
    ],
    hdrs = [
        "http.h",
        "url.h",
    ],
    include_prefix = "kj/compat",
    visibility = ["//visibility:public"],
    deps = [
        "//src/kj:kj-async",
        "@zlib",
    ],
)

cc_library(
    name = "kj-gzip",
    srcs = ["gzip.c++"],
    hdrs = ["gzip.h"],
    include_prefix = "kj/compat",
    visibility = ["//visibility:public"],
    deps = [
        "//src/kj:kj-async",
        "@zlib",
    ],
)

cc_library(
    name = "kj-brotli",
    srcs = ["brotli.c++"],
    hdrs = ["brotli.h"],
    include_prefix = "kj/compat",
    visibility = ["//visibility:public"],
    target_compatible_with = select({
        "//src/kj:use_brotli": [],
        "//conditions:default": ["@platforms//:incompatible"],
    }),
    deps = [
        "//src/kj:kj-async",
        "@brotli//:brotlienc",
        "@brotli//:brotlidec",
    ],
)

cc_library(
    name = "gtest",
    hdrs = ["gtest.h"],
    include_prefix = "kj/compat",
    visibility = ["//visibility:public"],
    deps = ["//src/kj"],
)

kj_tests = [
    "http-test.c++",
    "url-test.c++",
]

[cc_test(
    name = f.removesuffix(".c++"),
    srcs = [f],
    deps = [
        ":kj-http",
        "//src/kj:kj-test",
    ],
) for f in kj_tests]

cc_library(
    name = "http-socketpair-test-base",
    hdrs = ["http-test.c++"],
)

cc_test(
    name = "http-socketpair-test",
    srcs = ["http-socketpair-test.c++"],
    deps = [
        ":http-socketpair-test-base",
        ":kj-http",
        "//src/kj:kj-test",
    ],
    target_compatible_with = [
        "@platforms//os:linux", # TODO: Investigate why this fails on macOS
    ],
)

kj_tls_tests = [
    "tls-test.c++",
    "readiness-io-test.c++",
]

[cc_test(
    name = f.removesuffix(".c++"),
    srcs = [f],
    target_compatible_with = select({
        "//src/kj:use_openssl": [],
        "//conditions:default": ["@platforms//:incompatible"],
    }),
    deps = [
        ":kj-tls",
        ":kj-http",
        "//src/kj:kj-test",
    ],
) for f in kj_tls_tests]

cc_test(
    name = "gzip-test",
    srcs = ["gzip-test.c++"],
    target_compatible_with = select({
        "//src/kj:use_zlib": [],
        "//conditions:default": ["@platforms//:incompatible"],
    }),
    deps = [
        ":kj-gzip",
        "//src/kj:kj-test",
    ],
)

cc_test(
    name = "brotli-test",
    srcs = ["brotli-test.c++"],
    target_compatible_with = select({
        "//src/kj:use_brotli": [],
        "//conditions:default": ["@platforms//:incompatible"],
    }),
    deps = [
        ":kj-brotli",
        "//src/kj:kj-test",
    ],
)
